package com.thiswhyme.mail.controller;

import com.thiswhyme.common.response.ResponseVo;
import com.thiswhyme.common.utils.CommonStringUtils;
import com.thiswhyme.mail.service.EmailSender;
import com.thiswhyme.mail.service.ExceptionEmailSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @description: 邮件发送控制层
 * @author: thiswhyme
 * @date: 2021/5/7
 */
@RestController
@RequestMapping("email")
public class EmailController {

    @Autowired
    private Map<String, EmailSender> emailSenders;

    @GetMapping("exception-send")
    public ResponseVo<Boolean> sendExceptionEmail() {
        EmailSender sender = emailSenders.get(CommonStringUtils.toLowerCaseFirst(ExceptionEmailSender.class.getSimpleName()));
        sender.send(null, "测试异常通知邮件发送", "自定义业务参数");
        return ResponseVo.success(true);
    }
}
